#include <bits/stdc++.h>

using namespace std;

// #define LOCK_GETCHAR
// #define USE_INT_128

#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
#endif

#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif

#define il inline
#define mkp make_pair
#define fi first
#define se second
#define ssz(x) (signed((x).size()))
#define _loop_i_t(j, k) make_signed_t<decltype((j) - (k))>
#define For(i, j, k) for (_loop_i_t(j, k) i = (j); i <= (k); ++i) // NOLINT
#define ForDown(i, j, k)                                                       \
  for (_loop_i_t(j, k) i = (j); i >= decltype(i)(k); --i) // NOLINT
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename)                                                       \
  freopen(filename ".in", "r", stdin);                                         \
  freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif

using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif

// clang-format off
CONSTEXPR_FUNC il ll qpow(ll x, ull y, ll mod){ ll ans = 1; x %= mod; while (y) { if (y & 1) (ans *= x) %= mod; (x *= x) %= mod; y >>= 1; } return ans; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y); }
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + (c - '0'); c = getchar(); } x *= f; }
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x), read(y...); }
// clang-format on

// File head end

namespace {
constexpr ll MAXN = 5e5 + 5;
int n, lst[MAXN];
vector<int> a[MAXN], len[MAXN], pool;
ll c, b[MAXN];
pll sum[MAXN * 4];
map<int, vector<int>> ti;
void Main() {
  FileIO("list");
  read(n);
  For(i, 1, n) {
    int sz;
    read(sz), a[i].resize(sz), len[i].resize(sz);
    For(j, 0, sz - 1) { read(a[i][j]), ti[a[i][j]].eb(i); }
    For(j, 0, sz - 1) {
      int nxt = (j + 1 == ssz(a[i])) ? (int(2e9) + 5) : a[i][j + 1];
      len[i][j] = nxt - a[i][j], pool.eb(len[i][j]), pool.eb(len[i][j] + 1);
    }
  }
  pool.eb(1);
  sort(pool.begin(), pool.end());
  pool.erase(unique(pool.begin(), pool.end()), pool.end());
  For(i, 1, n) For(j, 0, ssz(len[i]) - 1) {
    len[i][j] = lower_bound(pool.begin(), pool.end(), len[i][j]) - pool.begin();
  }
  read(c);
  For(i, 1, n) read(b[i]), b[i] *= i;
  For(i, 1, n) {
    For(j, 0, ssz(a[i]) - 1) {
      int len = ::len[i][j];
      sum[0].se += c;
      sum[len + 1].se -= c;
      sum[len + 1].fi += ll(c) * pool[len];
    }
  }
  // cerr << "ok part 0 " << ssz(pool) << ' ' << 1. * clock() / CLOCKS_PER_SEC
  //      << '\n';
  for (auto it = ti.begin(); it != ti.end(); ++it) {
    vector<int> qwq;
    int cnt = 0, tot = ssz(it->se);
    for (int p : it->se) {
      if (lst[p])
        qwq.eb(len[p][lst[p] - 1]);
      else
        cnt++;
      lst[p]++;
    }
    sort(qwq.begin(), qwq.end());
    sum[0].fi += b[tot];
    For(i, 0, ssz(qwq) - 1) {
      sum[qwq[i] + 1].fi += b[tot - i - 1] - b[tot - i];
    }
  }
  // cerr << "ok part 1 " << 1. * clock() / CLOCKS_PER_SEC << '\n';
  ll K = 0, B = 0, minv = ll(1e18) + 5;

  vector<int> ans;
  For(i, 0, ssz(pool) - 1) {
    K += sum[i].se, B += sum[i].fi;
    if (K > 0) {
      ll val = ll(pool[i]) * K + B;
      if (minv > val)
        minv = val, ans = {pool[i]};
      else if (minv == val)
        minv = val, ans.eb(pool[i]);
    } else if (K < 0) {
      if (i + 1 == ssz(pool))
        continue;
      ll val = ll(pool[i + 1] - 1) * K + B;
      if (minv > val)
        minv = val, ans = {pool[i + 1] - 1};
      else if (minv == val)
        minv = val, ans.eb(pool[i + 1] - 1);
    } else if (K == 0) {
      ll val = ll(pool[i]) * K + B;
      if (val > minv)
        continue;
      assert(i + 1 != ssz(pool));
      vector<int> cur(pool[i + 1] - pool[i]);
      iota(cur.begin(), cur.end(), pool[i]);
      if (minv > val)
        minv = val, ans = cur;
      else if (minv == val)
        minv = val, ans.insert(ans.end(), cur.begin(), cur.end());
    }
  }
  cout << minv << ' ' << ssz(ans) << '\n';
  for (int x : ans)
    cout << x << ' ';
  cout << '\n';
}
} // namespace

signed main() { return Main(), 0; }
